package com.briup.jz.web.controller;

import com.briup.jz.bean.ProductCategory;
import com.briup.jz.service.IProductCategoryService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Api(description="产品分类信息")
@RestController
@RequestMapping("/productcatagory")
public class ProductCategoryController {
    @Autowired
    private IProductCategoryService iProductCategoryService;
    @ApiOperation("查询产品分类信息")
    @GetMapping("/query")
    public Message query(Long id){
        List<ProductCategory> productCategories = iProductCategoryService.query(id);
        return MessageUtil.success(productCategories);
    }
    @ApiOperation("新建产品分类信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name" ,value = "名称", paramType = "form"),
            @ApiImplicitParam(name = "icon" ,value = "图标", paramType = "form"),
            @ApiImplicitParam(name = "num" ,value = "数量", paramType = "form"),
            @ApiImplicitParam(name = "parentId" ,value = "父类id", paramType = "form")
    })
    @PostMapping("/saveorupdate")
    public Message saveOrUpdate(ProductCategory productCategory){
        iProductCategoryService.saveOrUpdate(productCategory);
        return MessageUtil.success("操作成功");
    }
    @ApiOperation("删除产品分类信息")
    @GetMapping("/delete")
    public Message delete(Long id){
        iProductCategoryService.deleteById(id);
        return  MessageUtil.success("操作成功");
    }
}
